package java_0482_Arrays;

import java.util.Arrays;
import java.util.Comparator;

public class ArraysSortCustom {
    public static void main(String[] args) {
        int[] arr = new int[]{1, 0, -1, 20};
        bubble02(arr, new Comparator() {
                    @Override
                    public int compare(Object o1, Object o2) {
                        int n1 = (Integer) o1;
                        int n2 = (Integer) o2;
                        return n1 - n2;
                    }
                }
        );
        System.out.println(Arrays.toString(arr));
    }

    //结合冒泡+定制
    public static void bubble02(int[] arr, Comparator c) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (c.compare(arr[j], arr[j + 1]) > 0) {
                    int temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    }
 }
